﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Threading;
using Hi_Baidu.ProcessModel;

namespace Hi_Baidu.Timer
{
    class UpdateItemTimeOutEvent : TimeOutEvent
    {
        private byte[] username;
        private TreeViewItem item;
        private byte[] NewValue;
        private delegate void UPDATE_ITEM(byte[] username, TreeViewItem item, byte[] NewValue);

        public UpdateItemTimeOutEvent(byte[] username, TreeViewItem item, byte[] NewValue, String Key, int Interval, int TryCount)
            : base(Key, Interval, TryCount)
        {
            this.username = username;
            this.item = item;
            this.NewValue = NewValue;
            this.OnTryFull += new EventHandler<EventArgs>(UpdateItemTimeOutEvent_OnTryFull);
            this.OnTick += new EventHandler<EventArgs>(UpdateItemTimeOutEvent_OnTick);
        }

        void UpdateItemTimeOutEvent_OnTick(object sender, EventArgs e)
        {
            //重试更新分组操作
            System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Background,
                                                                 new UPDATE_ITEM(
                                                                     Hi_Baidu.ProcessModel.UpdateProcessModel.UpdateItem),
                                                                 this.username,
                                                                 new object[]
                                                                             {
                                                                                 this.item,
                                                                                 this.NewValue
                                                                             });
        }

        void UpdateItemTimeOutEvent_OnTryFull(object sender, EventArgs e)
        {
            System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new PUBLIC_DELEGATE(Globle.ShowWindow));
        }
    }
}
